package com.example.carapi.mapper;

import com.example.carapi.bean.CarConfig;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CarConfigMapper {

    @Select("select *\n" +
            "from car_config\n" +
            "where id=#{id}")
    CarConfig getOne(@Param("id") Long id);

    @Select("select *\n" +
            "from car_config")
    List<CarConfig> getAll();

    // 数据库已经设置了主键自增，不需要手动插入id了
    @Insert("insert\n" +
            "into car_config\n" +
            "values (name=#{name}, value=#{value}, model_id=#{model_id})")
    void insert(CarConfig carConfig);

    @Update("update car_config\n" +
            "set name=#{name}, value=#{value}, model_id=#{model_id}\n" +
            "where id=#{id}")
    void update(CarConfig carConfig);

    @Delete("delete\n" +
            "from car_config\n" +
            "where id=#{id}")
    void delete(@Param("id") Long id);
}
